package cn.baage.campus.controller;

import cn.baage.campus.model.vo.CommentAddReqVO;
import cn.baage.campus.model.vo.CommentResVO;
import cn.baage.campus.service.CommentService;
import cn.baage.campus.utils.Result;
import cn.baage.campus.utils.ResultPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description: 评论接口
 * @Author: 八阿哥
 * @url: baage.cn
 * @Version: 1.0
 **/
@RestController
@RequestMapping("/comment")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Api(tags = "评论接口")
public class CommentController {

    private final CommentService commentService;

    @PostMapping("/addComment")
    @ApiModelProperty(value = "新增评论")
    public Result<Object> addComment(@RequestBody CommentAddReqVO commentAddReqVO) {
        commentService.addComment(commentAddReqVO);
        return Result.success();
    }


    @GetMapping("/listComment")
    @ApiModelProperty(value = "查询评论列表")
    @SuppressWarnings("unchecked")
    public ResultPage listComment(@RequestParam String postingId) {
        Map<String, Object> commentRes = commentService.listComment(postingId);
        Long total = (Long) commentRes.get("total");
        List<CommentResVO> row = (List<CommentResVO>)commentRes.get("rows");
        return ResultPage.success(total, row);
    }


}
